<template>
	<view class="login">
		<view class="avatar"><image src="../../static/icons/leju-logo.png" mode=""></image></view>
		<view class="form">
			<uni-easyinput type="number" placeholder="请输入手机号" class="input" v-model="fromData.username" />
			<uni-easyinput type="password" placeholder="请输入密码" class="input" v-model="fromData.password" passwordIcon></uni-easyinput>
		</view>
		<view class="loginBtn" @tap="handleDoLogin">登录</view>
		<view class="footer">
			<navigator url="../mine/resetPassword/resetPassword">找回密码</navigator>
			|
			<navigator url="../register/register">注册账户</navigator>
		</view>
	</view>
</template>

<script>
import { doLogin, getMemberInfo } from '../../api/login/index.js';
export default {
	data() {
		return {
			fromData: {
				username: '17596496508',
				password: '123456'
			}
		};
	},
	methods: {
		async handleDoLogin() {
			const { success, data } = await doLogin({ ...this.fromData });
			if (success) {
				uni.setStorageSync('token', data.token);
				const userInfoResp = await getMemberInfo();
				if (userInfoResp.success) {
					uni.setStorageSync('userinfo', userInfoResp.data.userInfo);
					uni.showToast({
						title: '登录成功,1s后跳转到个人中心'
					});
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/mine/mine'
						});
					}, 1000);
				}
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.login {
	overflow: hidden;
	// 头像
	.avatar {
		width: 160rpx;
		height: 160rpx;
		margin: 128rpx auto 72rpx;
		image {
			width: 100%;
			height: 100%;
			border-radius: 50%;
		}
	}
	// 输入框
	.form {
		display: flex;
		flex-direction: column;
		padding: 0 70rpx;

		.input {
			width: 100%;
			box-sizing: border-box;
			padding: 32rpx;
			box-shadow: 0 0 60rpx 0 rgba(43, 86, 112, 0.1);
			margin: 24rpx 0;
			border-radius: 60rpx;
			/deep/ .is-input-border {
				min-height: 0 !important;
				border: none;
			}
		}
	}
	.loginBtn {
		color: #fff;
		font-size: 30rpx;
		height: 100rpx;
		width: 600rpx;
		margin: 96rpx auto 0;
		text-align: center;
		line-height: 100rpx;
		border-radius: 100rpx;
		background-color: #354e44;
	}
	.footer {
		display: flex;
		justify-content: center;
		margin-top: 64rpx;
		font-size: 28rpx;
		color: rgba(0, 0, 0, 0.7);
		view {
			margin: 0 10rpx;
		}
	}
}
</style>
